const app = getApp();
const http = require('../../utils/http.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name: "",
    userInfo: null,
    isModal: false
  },
  onGetUserInfo: function (e) {
    if (e.detail.userInfo) {
      app.globalData.userInfo = e.detail.userInfo;
      this.setData({
        isModal: true
      })
    }
  },
  onGetPhoneNumber: function (e) {
    let postData = Object.assign(app.globalData.userInfo, {ivStr: e.detail.iv}, {encryptedData: e.detail.encryptedData});
    http.post('/api/user/saveMember', postData).then(res => {
      if (res.code == 200) {
        app.globalData.userInfo = Object.assign(app.globalData.userInfo, {mobile: res.result})
        wx.setStorageSync('userInfo', app.globalData.userInfo)
        wx.navigateBack({
          delta: 1
        })
      }
    })
  },
  hideModal: function (e) {
    this.setData({
      isModal: false
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      name: app.globalData.customerName
    })
  },

})
